/*-----------------------------------------------------
 * 权限子系统-在线用户模块
 * ---------------------------------------------------*/
jx.ready(function () {
    //定义变量
    var api = {
        grid: '/sys/onlineUser/grid',
        logoff: '/sys/onlineUser/logoff',
        details: '/sys/onlineUser/details'
    };
    var gridInstance;
    var $gridPanel;
    var $grid = $('#grid');
    // var $gridform = $('#gridform');
    //var dialogWidth = $grid.data('dialogWidth'),dialogHeight = $grid.data('dialogHeight');
    var detailsTitle = '查看在线用户';
    var gridUrl = jx.apiUrl(api.grid), logoffUrl = jx.apiUrl(api.logoff),
        detailsUrl = jx.apiUrl(api.details);

    //初始化表格
    var initGrid = function () {
        gridInstance = $grid.jxgrid({
            url: gridUrl,
            //pagination:false,
            onDblClickRow: function (index, row) {
                detailsData(row);
            }
        });
        $grid.datagrid('getPager').pagination({
            layout: ['info'],
            displayMsg: '共{total}条记录'
        });
        $gridPanel = gridInstance.getPanel();
    };

    //初始化事件
    var initEvent = function () {
        $('#btn-logoff').click(function () {
            logoffData();
        });

        //详情事件
        $gridPanel.on('click', '.cmd-details', function () {
            detailsData(gridInstance.getSelected());
        });
    };

    //注销
    var logoffData = function () {
        if (!gridInstance.hasCheckedRow()) return;
        var ids = gridInstance.getCheckedRowIds();
        jx.ajax({
            url: logoffUrl,
            data: {ids: ids.join()},
            confirm: '注：您确定要注销吗？',
            maskMsg: '正在注销,请稍等...',
            success: function (result) {
                gridInstance.reloadGridData();
                jx.toastr.success('注销成功');
            }
        });
    };

    //查看数据
    var detailsData = function (row) {
        jx.auth.detailsData(gridInstance, row, {
            title: detailsTitle,
            url: detailsUrl
        });
    };

    //定义表格列格式化函数
    jx.gf.details = function (v, row) {
        return jx.formatString('<a class="cmd-details">{0}</a>', v);
    };

    //对外接口 重新加载表格数据
    window.reloadGridData = function () {
        gridInstance.reloadGridData();
    };

    //初始化
    initGrid();
    initEvent();
});